<?php
header("content-type:text/html;charset=utf-8");
$redis=new Redis();
$redis->connect("127.0.0.1","6379");
$qg_id=$_POST['qg_id'];

$dsn="mysql:host=127.0.0.1;dbname=book;charset=utf8";
$pdo=new PDO($dsn,'root','root');
$sql="select number from qg where id=$id";
$res=$pdo->query($sql)->fetch();
if($redis->lPop("data".$qg_id))
{
    $sql="update qg set number =number-1 where qg_id=$qg_id";
    $info=$pdo->exec($sql);
    if($info)
    {
        $data=array('code'=>1,"msg"=>"抢购成功");

    }
    else
    {
        $data=array('code'=>0,"msg"=>"sorry,抢光了");
    }
    echo json_encode($data);
}

?>